home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#03 (Aug85-Sep85)
/
asm
/
asm Sound Vol. 1 #9
/
SoundOff
< prev
Wrap
Text File
|
1985-06-18
|
7KB
|
279 lines
*ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
*ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Sound Exercize #1 ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
*ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ (C) 1985 by Chris Yerga for MacTutor ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
*ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
INCLUDE MacTraps.D
; Declare external labels
XDEF START
;ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Define Macros ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
MACRO Center String,MidPT,Y =
CLR.W -(SP) ;Save room for INTEGER width of string
PEA '{String}'
_StringWidth
CLR.L D3 ;Clear the high word of D3 so the DIVU works
MOVE.W (SP)+,D3 ;Get the width (in pixels) in D3
DIVU #2,D3 ;Divide by 2
MOVE.L #{MidPT},D4
SUB.W D3,D4 ;Subtract (Width/2) from 103 to center text
MOVE.W D4,-(SP) ;Push the X coordinate
MOVE.W #{Y},-(SP) ;Push the Y coordinate
_MoveTo ;Position the pen
PEA '{String}'
_DrawString
| ;End of Macro
;ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Local Constants ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
AllEvents EQU $0000FFFF ; Mask for FlushEvents
MaxEvents EQU 12
DWindLen EQU $AA ; The size of a Dialog Record
;ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Start of Main Program ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
BadPtr: _Debugger ;Should never get here. Is called
;when there is a problem with the
;memory manager.
START: MOVEM.L D0-D7/A0-A6,-(SP) ;The standard-issue routine which
LEA SAVEREGS,A0 ;which saves the registers etc.
MOVE.L A6,(A0)
MOVE.L A7,4(A0)
;ŸŸŸŸŸŸŸŸŸŸŸŸŸ Initialize the ROM routines ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
PEA -4(A5) ;QD Global ptr
_InitGraf ;Init QD global
_InitFonts ;Init font manager
_InitWindows ;Init Window Manager
_InitMenus ;Guess what...you got it!
CLR.L -(SP) ;Standard SysErr/DS dialog
_InitDialogs ;Init Dialog Manger
_TEInit ;Init ROM Text edit
MOVE.L #AllEvents,D0 ;And flush ALL previous
_FlushEvents ;events
_InitCursor ;Get the standard arrow
;◊◊◊ Allocate the memory that we need ◊◊◊
MOVE.L #50,D0 ;Get a 50 Byte nonrelocatable block
_NewPtr
CMP #0,D0 ;Did we get the block??
BNE BadPtr ;Nope...jump to MacsBug
LEA ParamBlock,A1 ;Save the Ptr
MOVE.L A0,(A1)
MOVE.L #255,D0 ;Get a 255 byte block for waveform def
_NewPtr,CLEAR ;and fill it with zeros while you're at it
CMP #0,D0 ;Did we get the memory?
BNE BadPtr ;Nope...Debugger time
LEA Wave,A1 ;Save the Ptr
MOVE.L A0,(A1)
;◊◊◊ Set up the ioParamBlock fields ◊◊◊
MOVE.L ParamBlock,A0 ;Get the Ptr to ioParamBlock
CLR.L 12(A0) ;No completion routine
MOVE.W #-4,24(A0) ;The Sound Driver reference #
CLR.W 44(A0) ;Standard positioning
CLR.L 46(A0) ;No offset for the write
;◊◊◊ Fill the Wave buffer with a simple Square Wave definition ◊◊◊
MOVE.L Wave,A0 ;Get the base address of the block
MOVE.L #127,D0 ;Set up the wave definition
MakeWave:
MOVE.B #255,(A0)+ ;Set bytes 0-127 of the wave definition
;and increment A0
DBRA D0,MakeWave ;loop until 127...
;ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Set up the Dialog Box ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
CLR.L -(SP) ;Save room for DIalogPtr
MOVE.W #128,-(SP) ;The ResID of the dialog
PEA DStorage(A5) ;Where to put the DialogRec
MOVE.L #-1,-(SP) ;Put it in front, please...
_GetNewDialog
LEA DHandle,A2 ;Save handle, but keep it
MOVE.L (SP),(A2) ;on the stack
_DrawDialog ;Draw the dialog..
LEA DHandle,A2
MOVE.L (A2),-(SP) ;Set the Dialog to the current GrafPort
_SetPort
MOVE.W #7,-(SP) ;Select Athens
_TextFont
MOVE.W #18,-(SP) ;in 18Pt size
_TextSize
Center Sound Example #1,206,35 ;<- God this makes life easy!
MOVE.W #1,-(SP) ;Select Chicago
_TextFont
MOVE.W #12,-(SP) ;in 12Pt size
_TextSize
Center ©1985 Chris Yerga for MacTutor,206,52
;ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Main Event Loop ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
MAIN:
CLR.L -(SP) ;NIL for FilterProc
PEA ItemHit ;VAR ItemHit
_ModalDialog ;handle the dialog for us!
MOVE ItemHit,D0 ;Get the result
CMP #1,D0 ;Is it Square Wave?
BEQ Square ;Yes....
CMP #2,D0 ;Is it 4Tone?
BEQ FourTone ;You got it....
CMP #3,D0 ;Is it Bye Bye??
BEQ Adios ;Uh huh...
BRA Main ;Keep going till we get a valid event...
Square:
MOVE.L ParamBlock,A0 ;Get the Ptr to ioParamBlock
MOVE.L #SqEnd-SqBegin,36(A0) ;The length of the data, so we
;can tell the device manager how
;much to write
LEA SqBegin,A1 ;Ptr to our data buffer
MOVE.L A1,32(A0)
_Write ;this is the actual Write call.
;Be sure to have A0 pointing to
;your ioParamBlock!
BRA Main ;We're done for now....
SqBegin:
DC.W -1 ;This tells the sound driver that
;the data is for the square-wave
;driver.
;Play the C major diatonic scale...
DC.W 5937,128,20 ;C
DC.W 5278,128,20 ;D
DC.W 4750,128,20 ;E
DC.W 4453,128,20 ;F
DC.W 3958,128,20 ;G
DC.W 3562,128,20 ;A
DC.W 3167,128,20 ;B
DC.W 2969,128,20 ;C
DC.W 3167,128,20 ;B
DC.W 3562,128,20 ;A
DC.W 3958,128,20 ;G
DC.W 4453,128,20 ;F
DC.W 4750,128,20 ;E
DC.W 5278,128,20 ;D
DC.W 5937,128,20 ;C
DC.W 0,0,0
SqEnd: DC.W 0 ;End of the data
FourTone:
MOVE.L ParamBlock,A0 ;Get the Ptr to our ioParamBlock
MOVE.L #6,36(A0) ;ioCount (how many bytes to write)
;in this case always 6 bytes
MOVE.L Wave,A2 ;Get the Ptr to the waveshape def
LEA FTSynthRec,A1 ;Get the Ptr to the sound table
MOVE.L #3,D0 ;Loop 4 times
SetWave:
MOVE.W #30,(A1) ;Set the tone length to .5 seconds
ADDA #34,A1 ;Adjust A1 to point to WavePtr fields
MOVE.L A2,(A1)+ ;Set 1st WavePtr
MOVE.L A2,(A1)+ ;Set 2nd WavePtr
MOVE.L A2,(A1)+ ;Set 3rd WavePtr
MOVE.L A2,(A1)+ ;Set 4th WavePtr
DBRA D0,SetWave
LEA FTBegin,A3 ;Set the BuffPtr in the ParamBlock
MOVE.L A3,32(A0) ;to point to our data buffer
LEA FTSynthRec,A2 ;Set the FTSRecPtr in the Data
MOVE.L #3,D3 ;Loop 4 times
FTLoop:
MOVE.L A2,2(A3) ;Set the pointer to point to the
;next sound
MOVE.L ParamBlock,A0 ;Get Ptr to ioParamBlock in A0
_Write ;Write it!
ADDA #50,A2 ;Point to the next tone record
DBRA D3,FTLoop ;and loop...
BRA Main ;Thank you...
;The four-tone record is unique in that it is not actually written to
;the sound driver. Rather, only a ptr to the actual tones is written.
;This means that only one set of 4 tones can be written at a time.
FTBegin:
DC.W 1 ;Four tone = 1
DC.L 0 ;Holder for Ptr to the actual tones
FTSynthRec:
DC.W 60 ;Do sound for 1 sec
DC.L $3CBB0,0
DC.L $5B188,0
DC.L $4DBC3,0
DC.L $00000,0
DC.L 0,0,0,0 ;Place holders for WavePtr's
DC.W 60 ;Do sound for 1 sec
DC.L $36A85,0
DC.L $50F95,0
DC.L $6D50A,0
DC.L $00000,0
DC.L 0,0,0,0 ;Place holders for WavePtr's
DC.W 75 ;.5 SEC
DC.L $287CA,0
DC.L $3CBB0,0
DC.L $30959,0
DC.L $00000,0
DC.L 0,0,0,0
DC.W 30
DC.L $1E5D8,0
DC.L $287CA,0
DC.L $30959,0
DC.L $00000,0
DC.L 0,0,0,0
ADIOS:
LEA SaveRegs,A0
MOVE.L (A0),A6
MOVE.L 4(A0),A7
MOVEM.L (SP)+,D0-D7/A0-A6
RTS
;ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Program Variables ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
SaveRegs: DCB.L 2,0 ;For saving the SP etc..
DHandle: DC.L 0 ;For the dialog Handle
ItemHit: DC.W 0 ;For _ModalDialog
ParamBlock: DC.L 0 ;For the ioPB
Wave: DC.L 0 ;For the WaveShape definition
;ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ Dialog Record ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ
DStorage: DS.W DWindLen